package com.jingdianjichi.subject.domain.Handler.subject;

import com.jingdianjichi.subject.common.enums.IsDeletedCodeEnum;
import com.jingdianjichi.subject.common.enums.SubjectInfoTypeCodeEnum;
import com.jingdianjichi.subject.domain.entity.SubjectInfoBo;
import com.jingdianjichi.subject.infra.basic.entity.SubjectMultiple;
import com.jingdianjichi.subject.infra.basic.service.SubjectMultipleService;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.LinkedList;
import java.util.List;

@Component
public class MultipleTypeHandler implements SubjectTypeHandler{

    @Resource
    private SubjectMultipleService subjectMultipleService;

    @Override
    public SubjectInfoTypeCodeEnum getHandlerType() {
        return SubjectInfoTypeCodeEnum.MULTIPLE;
    }

    @Override
    public void add(SubjectInfoBo subjectInfoBO) {
        //多选题目的插入
        List<SubjectMultiple> subjectMultipleList = new LinkedList<>();
        subjectInfoBO.getOptionList().forEach(option -> {
            SubjectMultiple subjectMultiple = new SubjectMultiple();
            BeanUtils.copyProperties(option,subjectMultiple);
            subjectMultiple.setSubjectId(subjectInfoBO.getId());
            subjectMultiple.setIsDeleted(IsDeletedCodeEnum.UN_DELETED.getCode());
            subjectMultipleList.add(subjectMultiple);
        });
        subjectMultipleService.batchInsert(subjectMultipleList);
    }

//    @Override
//    public SubjectOptionBO query(int subjectId) {
//        SubjectMultiple subjectMultiple = new SubjectMultiple();
//        subjectMultiple.setSubjectId(Long.valueOf(subjectId));
//        List<SubjectMultiple> result = subjectMultipleService.queryByCondition(subjectMultiple);
//        List<SubjectAnswerBO> subjectAnswerBOList = MultipleSubjectConverter.INSTANCE.convertEntityToBoList(result);
//        SubjectOptionBO subjectOptionBO = new SubjectOptionBO();
//        subjectOptionBO.setOptionList(subjectAnswerBOList);
//        return subjectOptionBO;
//    }

}
